package com.foreverwin.jzymes.app.controller;

import com.foreverwin.jzymes.app.service.ILoginAdviceService;
import com.foreverwin.jzymes.framework.annotation.ParamBind;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app")
public class LoginController {

    @Autowired
    ILoginAdviceService loginAdviceService;

    @RequestMapping("/login")
    @ParamBind
    public AjaxResult login( String userId, String password ){

        try {
            loginAdviceService.authenticateUser( userId, password );
            return AjaxResult.success().put( "site", loginAdviceService.findSiteByUserId( userId ) );
        } catch (Exception e) {
            return AjaxResult.error( e.getMessage() );
        }
    }
}
